Make get_selected_file() return a ref'ed file
authorFederico Mena Quintero <federico@novell.com>
Fri, 11 Sep 2009 17:44:21 +0000 (12:44 -0500)
committerBenjamin Otte <otte@gnome.org>
Thu, 15 Oct 2009 20:06:18 +0000 (22:06 +0200)
The old semantics was to return a GFile* owned by the file system model; the new
semantics is to hand out new references whenever possible.

Signed-off-by: Federico Mena Quintero <federico@novell.com>
gtk/gtkfilechooserdefault.c

index a128e1d3973e11d57d32eede20740af9e8c39a37..f0c108fdfabb8529201993e6cbe81d810562db19 100644 (file)
@@ -2719,11 +2719,16 @@ get_selected_file_foreach_cb (GtkTreeModel *model,
 {
   struct get_selected_file_closure *closure = data;
 
+  if (closure->file)
+    {
+      /* Just in case this function gets run more than once with a multiple selection; we only care about one file */
+      g_object_unref (closure->file);
+      closure->file = NULL;
+    }
+
   gtk_tree_model_get (model, iter,
-                      MODEL_COL_FILE, &closure->file,
+                      MODEL_COL_FILE, &closure->file, /* this will give us a reffed file */
                       -1);
-  if (closure->file)
-    g_object_unref (closure->file);
 }
 
 /* Returns a selected path from the file list */
@@ -2794,6 +2799,8 @@ bookmarks_check_add_sensitivity (GtkFileChooserDefault *impl)
 
       file = get_selected_file (impl);
       active = file && all_folders && (shortcut_find_position (impl, file) == -1);
+      if (file)
+       g_object_unref (file);
     }
   else
     active = all_folders;